package org.zhaozhen.pet.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.zhaozhen.basic.service.impl.BaseServiceImpl;
import org.zhaozhen.basic.util.PageList;
import org.zhaozhen.org.domain.Employee;
import org.zhaozhen.org.mapper.EmployeeMapper;
import org.zhaozhen.pet.domain.Pet;
import org.zhaozhen.pet.domain.PetDetail;
import org.zhaozhen.pet.mapper.PetDetailMapper;
import org.zhaozhen.pet.mapper.PetMapper;
import org.zhaozhen.pet.query.PetQuery;
import org.zhaozhen.pet.service.IPetService;
import org.zhaozhen.user.domain.Logininfo;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;

@Service
public class PetServiceImpl  extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;
    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void add(Pet pet){
        petMapper.save(pet);
        PetDetail detail = pet.getDetail();
        if (detail!=null){
            detail.setPet_id(pet.getId());
            petDetailMapper.save(detail);
        }
    }

    @Override
    public void onsale(List<Long> ids) {
        //创建一个map对象
        Map<String,Object> map = new HashMap<>();
        map.put("ids", ids);
        map.put("onsaletime",new Date());
        petMapper.onsale(map);
    }

    @Override
    public void offsale(List<Long> ids) {
        //创建一个map对象
        Map<String,Object> map = new HashMap<>();
        map.put("ids", ids);
        map.put("offsaletime", new Date());
        petMapper.offSale(map);
    }

    @Override
    public Pet loadById(Long id) {
        return petMapper.loadByIdDetail(id);
    }

    @Override
    public PageList<Pet> queryPage2(PetQuery query, Logininfo currentLogin) {
        Employee employee = employeeMapper.loadByLogininfo_id(currentLogin.getId());
        if (employee!=null){
            query.setShopId(employee.getShop_id());
        }
        return super.queryPage(query);
    }


}
